package com.android.phoenix.activity.changeInfo;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.phoenix.Constant;
import com.android.phoenix.MainApplication;
import com.android.phoenix.R;
import com.android.phoenix.activity.BaseActivity;

public class ChangeNameActivity extends BaseActivity{
	private TextView tvCenter;
	private ImageView imgBack; 
	private SharedPreferences mShare;
	private Button btnConfirm;
	private EditText etName;
	private String nickName;
	private TextView title_txt_right_up;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acti_user_change_name);
		mShare = MainApplication.mSharedPreferences;
		tvCenter = (TextView) findViewById(R.id.title_txt_center);
		tvCenter.setText(getResources().getString(R.string.txt_myinfo_change_name));
		
		title_txt_right_up = (TextView) findViewById(R.id.title_txt_right_up);
		title_txt_right_up.setVisibility(View.GONE);
		
		etName = (EditText) findViewById(R.id.etName);
		
		if("".equals(mShare.getString(Constant.NICKNAME, ""))){
			etName.setHint(mShare.getString(Constant.USERNAME, ""));
		} else {
			etName.setHint(mShare.getString(Constant.NICKNAME, ""));
		}
		
		
		etName.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence str, int arg1, int arg2, int arg3) {
				nickName = str.toString().trim();
			}
			
			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
					int arg3) {
			}
			
			@Override
			public void afterTextChanged(Editable arg0) {
			}
		});
		nickName = etName.getText().toString().trim();
		
		btnConfirm = (Button) findViewById(R.id.btnConfirm);
		
		imgBack = (ImageView) findViewById(R.id.title_Imgbtn_left_up);
		imgBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		btnConfirm.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(!"".equals(nickName)){
					mShare.edit().putString(Constant.NICKNAME, nickName).commit();
				}
				finish();
			}
		});
		
	}
}
